import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'unit'
})
export class UnitPipe implements PipeTransform {
  constructor() {
  }

  transform(value: any, unit: string, divisionNumber: number, context?: any): string {
    try {
      let res;
      if (divisionNumber) {
        const _cal = Math.round(parseInt(value, 0) / divisionNumber);
        res = _cal.toString() + unit;
      } else {
        res = value.toString() + unit;
      }
      return res;
    } catch (e) {
    }
  }
}
